﻿/*
 * 由SharpDevelop创建。
 * 用户： Admin
 * 日期: 2025/5/4
 * 时间: 18:03
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.Collections.Generic;

namespace JCommand
{
	/// <summary>
	/// 替代AddonJs执行后台指令，由Js输出关键字 [J-COMMAND] 进行触发
	/// </summary>
	public static class JCommand
	{
		public static BDSCSBox.DataAdapter handle = null;
		
		static bool onReciver(string msg){
			int i = msg.IndexOf("[J-COMMAND]");
			if (i > 0) {
				if (msg.IndexOf("[Scripting] [J-COMMAND]") > -1) {
					string cmd = msg.Substring(i + "[J-COMMAND]".Length);
					if (handle != null)
						handle.sendMsg(cmd);
				}
			}
			return true;
		}
		
		public static BDSCSBox.TYPES.F_FUNC reciver = onReciver;
	}
}

namespace BDSCSBox {
	public class CSL {
		public bool onStart(BDSCSBox.DataAdapter handle) {	// dll入口，注册所有函数
			JCommand.JCommand.handle = handle;
			handle.addDataReceiver(JCommand.JCommand.reciver);
			Console.WriteLine("[JCommand] 代替AddonJs后台执行指令JCommand已加载。");
			return true;
		}
	}
}